package com.plateno.service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

@Service
public class SensitiveWordService {

	@Resource
	IKAnalzyerService ikAnalzyerService;
	
	/**
	 * ik分词
	 * 判断该词是否是敏感词
	 * 返回敏感词列表
	 * @param test
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public List wordFilterByIK(String test){
		Set<String> sourceWords =  ikAnalzyerService.analzyer(test);
		Iterator<String> iterator = sourceWords.iterator();
		List<String> result = new ArrayList<String>();
		String word = null;
//		long st = System.currentTimeMillis();
		while (iterator.hasNext()) {
			word = iterator.next();
			if (SensitivewordEngineService.checkSensitiveWordd(word)) {
				result.add(word);
			}
		}
//		System.out.println("IK过滤词耗时"+(System.currentTimeMillis() - st));
		return result;
	}
	
	
	
	@SuppressWarnings("rawtypes")
	public Set wordFilterByDFA(String test){
		return SensitivewordEngineService.getSensitiveWord(test, 2);
	}
	
	
	
}
